import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import axios from "axios";

import MintUI, { Indicator } from "mint-ui";
import "mint-ui/lib/style.css";

// import { Indicator } from "mint-ui";

Vue.use(MintUI);

Vue.prototype.$axios = axios;
Vue.config.productionTip = false;

// 给 axios 添加一个转换器，拦截请求
axios.interceptors.request.use(
  (config) => {
    Indicator.open();
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 拦截响应
axios.interceptors.response.use(
  (response) => {
    Indicator.close();
    return response;
  },
  (error) => {
    Indicator.close();
    return Promise.reject(error);
  }
);

// 注册一个全局自动聚焦的自定义指令
Vue.directive("focus", {
  inserted: (el) => {
    el.focus();
  }
});

new Vue({
  router,
  store,
  render: (h) => h(App)
}).$mount("#app");
